<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="120px">
			<el-form-item label="移位任务编号" prop="boxMoveNo">
				<el-input v-model="queryParams.boxMoveNo" placeholder="请输入移位任务编号" clearable
					@keyup.enter="handleQuery" />
			</el-form-item>
			<el-form-item label="档案盒号" prop="boxNo">
				<el-input v-model="queryParams.boxNo" placeholder="请输入档案盒号" clearable @keyup.enter="handleQuery" />
			</el-form-item>
			<!-- <el-form-item label="原库位号" prop="oldHouseLocationNo">
        <el-input
          v-model="queryParams.oldHouseLocationNo"
          placeholder="请输入原库位号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item> -->
			<el-form-item label="新库位号" prop="newHouseLocationNo">
				<el-input v-model="queryParams.newHouseLocationNo" placeholder="请输入新库位号" clearable
					@keyup.enter="handleQuery" />
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
				<el-button icon="Refresh" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-row :gutter="10" class="mb8">
			<el-col :span="1.5">
				<el-button type="warning" plain icon="Download" @click="handleExport"
					v-hasPermi="['archive:ArchiveBoxMove:export']">导出</el-button>
			</el-col>
			<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>

		<el-table v-loading="loading" :data="ArchiveBoxMoveList" @selection-change="handleSelectionChange">
			<el-table-column label="序号" align='center' width="50">
				<template #default="scope">
					{{ scope.$index+1 }}
				</template>
			</el-table-column>
			<el-table-column label="移位任务编号" align="center" prop="boxMoveNo" />
			<el-table-column label="档案盒号" align="center" prop="boxNo" />
			<!-- <el-table-column label="原库位号" align="center" prop="oldHouseLocationNo" /> -->
			<el-table-column label="新库位号" align="center" prop="newHouseLocationNo" />
			<el-table-column label="移位状态" align="center" prop="boxMoveStatus">
				<template #default="scope">
					<dict-tag :options="shift_status" :value="scope.row.boxMoveStatus" />
				</template>
			</el-table-column>
			<el-table-column label="创建时间" align="center" prop="createT	ime" width="160">
				<template #default="scope">
					<span>{{ parseTime(scope.row.createTime) }}</span>
				</template>
			</el-table-column>
		</el-table>
		<pagination v-show="total>0" :total="total" v-model:page="queryParams.pageNum"
			v-model:limit="queryParams.pageSize" @pagination="getList" />
	</div>
</template>

<script setup name="ArchiveBoxMove">
	import {
		listArchiveBoxMove,
		getArchiveBoxMove,
		delArchiveBoxMove,
		addArchiveBoxMove,
		updateArchiveBoxMove
	} from "@/api/archive/ArchiveBoxMove";
	import {
		getCurrentInstance,
		reactive,
		ref,
		toRefs
	} from "vue";
	const {
		proxy
	} = getCurrentInstance();
	const {
		push_status,
		execut_result,
		shift_status
	} = proxy.useDict('push_status', 'execut_result', 'shift_status');
	const ArchiveBoxMoveList = ref([]);
	const open = ref(false);
	const loading = ref(true);
	const showSearch = ref(true);
	const ids = ref([]);
	const single = ref(true);
	const multiple = ref(true);
	const total = ref(0);
	const title = ref("");
	const data = reactive({
		form: {},
		queryParams: {
			pageNum: 1,
			pageSize: 10,
			boxMoveNo: null,
			boxNo: null,
			oldHouseLocationNo: null,
			newHouseLocationNo: null,
			boxFullStatus: null
		},
		rules: {}
	});
	const {
		queryParams,
		form,
		rules
	} = toRefs(data);

	/** 查询盒移位列表 */
	function getList() {
		loading.value = true;
		listArchiveBoxMove(queryParams.value).then(response => {
			ArchiveBoxMoveList.value = response.rows;
			total.value = response.total;
			loading.value = false;
		});
	}

	// 取消按钮
	function cancel() {
		open.value = false;
		reset();
	}

	// 表单重置
	function reset() {
		form.value = {
			id: null,
			taskId: null,
			boxNo: null,
			oldHouseLocationNo: null,
			newHouseLocationNo: null,
			boxFullStatus: "0"
		};
		proxy.resetForm("ArchiveBoxMoveRef");
	}

	/** 搜索按钮操作 */
	function handleQuery() {
		queryParams.value.pageNum = 1;
		getList();
	}

	/** 重置按钮操作 */
	function resetQuery() {
		proxy.resetForm("queryRef");
		handleQuery();
	}

	// 多选框选中数据
	function handleSelectionChange(selection) {
		ids.value = selection.map(item => item.id);
		single.value = selection.length != 1;
		multiple.value = !selection.length;
	}

	/** 新增按钮操作 */
	function handleAdd() {
		reset();
		open.value = true;
		title.value = "添加盒移位";
	}

	/** 修改按钮操作 */
	function handleUpdate(row) {
		reset();
		const id = row.id || ids.value
		getArchiveBoxMove(id).then(response => {
			form.value = response.data;
			open.value = true;
			title.value = "修改盒移位";
		});
	}

	/** 提交按钮 */
	function submitForm() {
		proxy.$refs["ArchiveBoxMoveRef"].validate(valid => {
			if (valid) {
				if (form.value.id != null) {
					updateArchiveBoxMove(form.value).then(response => {
						proxy.$modal.msgSuccess("修改成功");
						open.value = false;
						getList();
					});
				} else {
					addArchiveBoxMove(form.value).then(response => {
						proxy.$modal.msgSuccess("新增成功");
						open.value = false;
						getList();
					});
				}
			}
		});
	}

	/** 删除按钮操作 */
	function handleDelete(row) {
		const ids = row.id || ids.value;
		proxy.$modal.confirm('是否确认删除盒移位编号为"' + ids + '"的数据项？').then(function() {
			return delArchiveBoxMove(ids);
		}).then(() => {
			getList();
			proxy.$modal.msgSuccess("删除成功");
		}).catch(() => {});
	}

	/** 导出按钮操作 */
	function handleExport() {
		proxy.download('archive/ArchiveBoxMove/export', {
			...queryParams.value
		}, `档案盒移位详情记录_${new Date().getTime()}.xlsx`)
	}

	getList();
</script>
